﻿using Yxinmt.Interface;
using System;
using System.Collections.Generic;
using System.Windows;

namespace Yxinmt.Controls
{
    public class Canvas : BaseControl, IControl
    {
        private System.Windows.Controls.Canvas _Canvas { get; set; }

        public Canvas(Dictionary<string, object> property, IComponent component)
        {
            Property = property;
            _Component = component;

            _Canvas = new System.Windows.Controls.Canvas();
            this.Element = _Canvas;

            InitSet();
            this.SetProperty();
            this.SetControlProperty(false, false);
        }

        public override void Add(System.Windows.FrameworkElement control)
        {
            _Canvas.Children.Add(control);

        }

        public override void Remove(FrameworkElement element)
        {
            _Canvas.Children.Remove(element);
        }

        public override void Clear()
        {
            if (_Canvas.Children.Count > 0) _Canvas.Children.Clear();
        }

        private void SetProperty()
        {
        }

        protected override void SetProperty(string name, object value)
        {
            System.Windows.Controls.Canvas c = _Canvas;
            switch (name)
            {
                case "name": c.Name = string.Concat("grid_", (string)value); break;
                case "Height": c.Height = Convert.ToDouble(value); break;
                case "Width": c.Width = Convert.ToDouble(value); break;
                case "Dock": System.Windows.Controls.DockPanel.SetDock(c, this.GetDock((string)value)); break;
                case "BackColor": c.Background = GetColor((string)value); break;
                case "ControlAlign": SetControlAlign((string)value); break;
                case "Visible": SetVisible(Convert.ToBoolean(value)); break;
                case "GridRowColumn": SetGridRowColumn((string)value); break;
                case "BackImageUrl": SetBackgroundImage((string)value); break;
                case "ZIndex": SetZIndex(Convert.ToInt32(value)); break;
            }
        }
    }
}
